<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>订单信息</title>
<%@ include file="../../header_inc.jsp" %>
<script type="text/javascript" src="${ctx}/js/other.js"></script>

</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height:0px;background:#EEEEEE;padding:0px">
		<form id="formModule" method="post">                  
                                  订单号：<input id="orderNo" onchange="searchit();"   class="easyui-validatebox textbox" type="text" name="orderNo" style="width:150px"></input>                                                 
                           
                              支付状态：<select id="payStatus" name="payStatus" onchange="searchit();">
                              <option value=""  >全部</option>
                           <option value="1" >已支付</option>
							<option value="2">未支付</option>
                </select>           
                      送货状态：<select id="sendStatus" name="sendStatus" onchange="searchit();">
                            <option value=""  >全部</option>
                         	<option value="1">下单</option>
							<option value="3" >已确认</option>
							<option value="4" >已完成</option>
							<option value="0" >已取消</option>
                </select>    
                时间从：<input class="easyui-datebox" size="15" name="begin_time" id="begindate"
			data-options="formatter:myformatter,parser:myparser"></input>
			&nbsp;
			到：<input class="easyui-datebox" size="15" name="end_time" id="enddate"
			data-options="formatter:myformatter,parser:myparser"></input>
		 	 &nbsp;&nbsp;
                <a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-search',plain:true" onclick="searchit()">查询</a>   
    	</form>  
	
	 

	</div>
	<div data-options="region:'center',title:''">
	   <div id="toolbar" style="height: auto">
			
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true" onclick="append()">添加</a> -->
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-remove',plain:true" onclick="edit()">修改</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-save',plain:true" onclick="removeit()">移除</a> -->
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-undo',plain:true" onclick="deleteit()">删除</a>
		</div> 
				<table id="dg" class="easyui-datagrid" title="" fit="true" style="width:700px;height:250px"
				data-options="rownumbers:true,singleSelect:true,url:'/manage/order/dataGrid',method:'get',toolbar:'#toolbar',fit:true,
				showFooter:false,singleSelect:false,pagination:true,idField:'orderId',onClickCell:onClickCell">
			<thead>
				<tr>
					  <th data-options="field:'ck',checkbox:true">全选</th> 
					<!-- <th data-options="field:'commodityInfo',width:120,align:'center',formatter:function comm(r){ return r.names; }">餐品名称</th> -->
					<th data-options="field:'orderNo',width:240,align:'center'">订单号</th>
					<!-- <th data-options="field:'serialNumber',width:160,align:'center'">流水号</th> -->
					<th data-options="field:'orderNumber',width:80,align:'center'" >订单数量</th>
					<th data-options="field:'payPrice',width:80,align:'center'">应付金额</th>
					<th data-options="field:'payWay',width:80,align:'center',formatter:zhifu">支付方式</th>
					<th data-options="field:'payStatus',width:80,align:'center',formatter:payStatus">支付状态</th>
					<th data-options="field:'orderDetail',width:80,align:'center',formatter:orderDetail"></th>
					<th data-options="field:'payTime',width:150,align:'center',formatter:formatDate ">下单时间</th>
					<th data-options="field:'userName',width:120,align:'center'">买家姓名</th><!-- ,formatter:function com(r){ return r.userName; }-->
					<th data-options="field:'phone',width:110,align:'center'">联系电话</th>
					<th data-options="field:'address',width:150,align:'center'">送货地址</th>
					<!-- <th data-options="field:'sysDepartment',width:130,align:'center' ,formatter:showDept">单位</th> -->
					<!-- <th data-options="field:'tag',width:150,align:'center'">买家留言</th> -->
					<th data-options="field:'sendStatus',width:60,align:'center',formatter:showsendstatus">操作</th>
	
				</tr>
		</table>
		<script type="text/javascript">
	/* 	 $(document).ready(function(){
				//获取当前用户可查看到的部门
				showDataInCombotree('${ctx }/manage/sysDepartment/getAllDepaetment?flag=2',$("#depId"),'${model.sysDepartment.depId}');
			  });
		//格式化日期 */
		function formatDate (strTime) {
			 var date = new Date(strTime);
			if(strTime == "" || strTime == null ){
				return "";
			}else{
				 return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
			}
			
		   
		   
		}
		function zhifu(value) {
			if (value == 1) {
				return "<font color='green'>微信支付</font>";
			} else if (value == 2)
				return "<font color='orange'>货到付款</font>";

		}

		function orderDetail(value){
			
			return "<a href='#' >订单详情</a>";
				
		}
		
	function onClickCell(index, field){
		  var s = "orderDetail";	
			if (field == s) {
				var nodeList = $('#dg').datagrid(
						'getRows');
				var orderNo = nodeList[index].orderNo
				console.log(nodeList[index].orderNo);
				var params = {
					    winId : 'win_orderDetail',
						title : '订单详情',
						width : 550,
						height : 420,
						showUrl : '${ctx}/manage/order/getOrderFrom?orderNo=' +orderNo,
						refresh_fun : function() {
							$('#dg').datagrid('uncheckAll');
							$('#dg').datagrid('reload');
						}
					};
				
				ShowUserFun(params);
				
				
			}  			
		}
	
	
		function payStatus(value){
			if(value==1){
				
				return "<font color='green'>已支付</font>";
				
			}
			else if(value==2){
				
				return "<font color='red'>未支付</font>";
				
			}
		}
		

			function confirmOrder() {

				var id = 0;
				var row = $('#dg').datagrid('getSelected');
				if(row != null){
					if (row.sendStatus == 1) {
						$.messager.confirm("确认订单", "是否确认订单", function(conf) {
						if(conf){
							id = row.orderId;
							var url = "${ctx}/manage/order/updateStatus?ids="
									+ id;

							$.getJSON(url, function(json) {
								if (json.success == 0) {
									$('#dg').datagrid('uncheckAll');
									$('#dg').datagrid('reload');
								} else {
									$.messager.alert("确认失败", json.msg);
								}
								
							});
						}
						});
					} else {
						$.messager.alert("提示", "该订单无需确认");
					}

				}else{
					$.messager.alert("提示", "请选择需要确认的订单");
				}
				
			}

			function clicke() {
				var id = 0;
				var row = $('#dg').datagrid('getSelected');
				$.messager.confirm("确认订单", "是否确认订单", function(conf) {
					if(conf){
					id = row.orderId;
					var url = "${ctx}/manage/order/updateStatus?ids=" + id;

					$.getJSON(url, function(json) {
						if (json.success == 0) {
							$('#dg').datagrid('uncheckAll');
							$('#dg').datagrid('reload');
						} else {
							$.messager.alert("确认失败", json.msg);
						}
					});
					}
				});
			}

			

			function showsendstatus(value, rec, index) {

				if (value == 1)
					return "<input class=\"btn\" type='button' onclick='clicke()' value='确认'/>";
				else if (value == 3)
					return "<font color='blue'>送货中</font>";
				else if (value == 4)
					return "<font color='gray'>交易完成</font>";
				else if (value == 0)
					return "<font color='red'>用户取消</font>";
			}
			function append() {
				var params = {
					winId : 'win_add_orderInfo',
					title : '添加订单信息',
					width : 400,
					height : 350,
					showUrl : '${ctx}/manage/order/add',
					refresh_fun : function() {
						$('#dg').datagrid('uncheckAll');
						$('#dg').datagrid('reload');
					}
				};
				open_fun(params);
			}

			function edit() {
				var id = 0;
				var row = $('#dg').datagrid('getSelected');
				var len = $('#dg').datagrid('getSelections').length;
				if (len > 1) {
					$.messager.alert("提示", "只能选择一个进行更改!");
				} else if (len == 1 && row) {
					id = row.orderId;
					var params = {
						winId : 'win_edit_orderInfo',
						title : '修改 订单信息',
						width : 450,
						height : 380,
						showUrl : '${ctx}/manage/order/edit?id=' + id,
						refresh_fun : function() {
							$('#dg').datagrid('uncheckAll');
							$('#dg').datagrid('reload');
						}
					};
					open_fun(params);
				} else {
					$.messager.alert("提示", "请选择要修改的信息!");
				}
			}
			function removeit() {
				var ids = [];
				var rows = $('#dg').datagrid('getSelections');
				var len = $('#dg').datagrid('getSelections').length;
				for (var i = 0; i < rows.length; i++) {
					ids.push(rows[i].orderId);
				}
				if (!len) {
					$.messager.alert("提示", "请选择要移除的数据！");
				} else {
					$.messager.confirm("移除确认", "是否要移除你选择的数据到回收站？", function(
							conf) {
						if (conf) {
							var url = "${ctx}/manage/order/remove?ids="
									+ ids;
							$.getJSON(url, function(json) {
								if (json.success == 0) {
									$('#dg').datagrid('uncheckAll');
									$('#dg').datagrid('reload');
								} else {
									showErrMsg(json);
								}
							});
						}
					});
				}
			}

			function deleteit() {
				var ids = [];
				var len = $('#dg').datagrid('getSelections').length;
				var rows = $('#dg').datagrid('getSelections');
				for (var i = 0; i < rows.length; i++) {
					ids.push(rows[i].orderId);
				}
				if (!len) {
					$.messager.alert("提示", "请选择要删除的数据！");
				} else {
					$.messager.confirm("删除确认", "是否要删除你选择的数据？", function(conf) {
						if (conf) {
							var url = "${ctx}/manage/order/delete?ids="
									+ ids;
							$.getJSON(url, function(json) {
								if (json.success == 0) {
									$('#dg').datagrid('uncheckAll');
									$('#dg').datagrid('reload');
								} else {
									$.messager.alert("删除失败", json.msg);
								}
							});
						}
					});
				}
			}

			function searchit() {
				$("#dg").datagrid("load",
						sy.serializeObject($('#formModule').form()));
			}
		</script>
	<%-- 	<div id="toolbar" style="height: auto">
			${buttons }
		</div>  --%>
	</div>
</body>
</html>